use std::env;
use log::LevelFilter;
// use std::env;
// use log::LevelFilter;
use simple_logger::SimpleLogger;

const DEF_LOG_LEVEL: LevelFilter = LevelFilter::Info;

pub async  fn logger_init() {
    // let level = match LevelFilter::from_str(cfg.log_level.to_uppercase().as_str()) {
    //     Ok(v) => { v }
    //     Err(e) => {
    //         println!("Parse loglevel '{}' failed: {}, use default level {}",
    //                  cfg.log_level.to_uppercase(), e, DEF_LOG_LEVEL);
    //         DEF_LOG_LEVEL
    //     }
    // };
    let mut level = DEF_LOG_LEVEL;
    if let Ok(env_level) = env::var("LOG_LVL") {
        level = match env_level.to_lowercase().as_str() {
            "trace" => LevelFilter::Trace,
            "debug" => LevelFilter::Debug,
            "info" => LevelFilter::Info,
            "warn" => LevelFilter::Warn,
            "error" => LevelFilter::Error,
            _ => DEF_LOG_LEVEL,
        };
    };


    // std::env::set_var("RUST_LOG", log_level);
    // println!("RUST_LOG level is {:?}", std::env::var("RUST_LOG"));
    // pretty_env_logger::try_init_timed();
    // println!("Current log level is {}", level.to_string());
    // SimpleLogger::new().with_colors(true).with_level(level).init().unwrap();
    // 在qca9531上发现bug报错，https://github.com/borntyping/rust-simple_logger/issues/48
    // 以下是workaround方法之一
    SimpleLogger::new().with_utc_timestamps().with_colors(true).with_level(level).init().unwrap();
}